﻿
Public Class FragenForm
    Public akt_la, akt_nr As Int16
    Dim falsch, richtig As Int16
    Dim la_akt(12), zufall As Boolean
    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LA_auswahl()
        Randomize()
        zufall = True
        Neue_Frage()
    End Sub
    
    Private Sub Neue_Frage()
        
        Dim neueFrage As Integer = 0
        Me.BackColor = System.Drawing.SystemColors.Control
        If ZufälligToolStripMenuItem.Checked Then
            Do
                Dim neue_aktiv As Boolean = False
                Dim vergleich As Integer = 0
                akt_la = 0
                neueFrage = CInt(Int((212) * Rnd() + 1))
                'MsgBox(neueFrage.ToString)
                Do
                    akt_la = akt_la + 1
                    vergleich = vergleich + StartForm.frag_an(akt_la)
                Loop Until neueFrage < (vergleich + 1)
                akt_nr = neueFrage - (vergleich - StartForm.frag_an(akt_la))

            Loop Until la_akt(akt_la)
            'MsgBox(akt_la)
            'MsgBox(akt_nr)
            'akt_nr = Int((StartForm.frag_an(akt_la) * Rnd()) + 1)
        Else
            If (StartForm.frag_an(akt_la) = (akt_nr)) Then
                akt_la = akt_la + 1
                akt_nr = 0
            End If

            Do While Not la_akt(akt_la)
                akt_la = akt_la + 1
                If akt_la > 12 Then
                    akt_la = 1
                End If
            Loop
            
            
            akt_nr = akt_nr + 1
        End If


        Label1.Text = StartForm.fragen(akt_la, akt_nr, 0)
        CheckBox1.Text = StartForm.fragen(akt_la, akt_nr, 1)
        CheckBox2.Text = StartForm.fragen(akt_la, akt_nr, 2)
        If StartForm.fragen(akt_la, akt_nr, 3) = "" Then
            CheckBox3.Visible = False
        Else
            CheckBox3.Visible = True
            CheckBox3.Text = StartForm.fragen(akt_la, akt_nr, 3)
        End If
        ToolStripStatusLabel2.Text = akt_la.ToString("D2") & "." & akt_nr.ToString("D2")
        Button1.Visible = True
        Button2.Visible = False
        CheckBox1.BackColor = Color.Transparent
        CheckBox2.BackColor = Color.Transparent
        CheckBox3.BackColor = Color.Transparent
        CheckBox1.Checked = False
        CheckBox2.Checked = False
        CheckBox3.Checked = False

        ToolStripStatusLabel1.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel2.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel3.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel4.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel5.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel6.BackColor = System.Drawing.SystemColors.Control
    End Sub

    Private Sub Frage_kontrollieren()
        Dim akt_richtig As Boolean = True
        Select Case (StartForm.fragen(akt_la, akt_nr, 4))
            Case 1
                CheckBox1.BackColor = Color.Green
                CheckBox2.BackColor = Color.Red
                CheckBox3.BackColor = Color.Red
                If CheckBox1.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox2.Checked = True Then
                    akt_richtig = False
                End If
                If CheckBox3.Checked = True Then
                    akt_richtig = False
                End If
            Case 2
                CheckBox1.BackColor = Color.Red
                CheckBox2.BackColor = Color.Green
                CheckBox3.BackColor = Color.Red
                If CheckBox1.Checked = True Then
                    akt_richtig = False
                End If
                If CheckBox2.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox3.Checked = True Then
                    akt_richtig = False
                End If
            Case 3
                CheckBox1.BackColor = Color.Green
                CheckBox2.BackColor = Color.Green
                CheckBox3.BackColor = Color.Red
                If CheckBox1.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox2.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox3.Checked = True Then
                    akt_richtig = False
                End If
            Case 4
                CheckBox1.BackColor = Color.Red
                CheckBox2.BackColor = Color.Red
                CheckBox3.BackColor = Color.Green
                If CheckBox1.Checked = True Then
                    akt_richtig = False
                End If
                If CheckBox2.Checked = True Then
                    akt_richtig = False
                End If
                If CheckBox3.Checked = False Then
                    akt_richtig = False
                End If
            Case 5
                CheckBox1.BackColor = Color.Green
                CheckBox2.BackColor = Color.Red
                CheckBox3.BackColor = Color.Green
                If CheckBox1.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox2.Checked = True Then
                    akt_richtig = False
                End If
                If CheckBox3.Checked = False Then
                    akt_richtig = False
                End If
            Case 6
                CheckBox1.BackColor = Color.Red
                CheckBox2.BackColor = Color.Green
                CheckBox3.BackColor = Color.Green
                If CheckBox1.Checked = True Then
                    akt_richtig = False
                End If
                If CheckBox2.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox3.Checked = False Then
                    akt_richtig = False
                End If
            Case 7
                CheckBox1.BackColor = Color.Green
                CheckBox2.BackColor = Color.Green
                CheckBox3.BackColor = Color.Green
                If CheckBox1.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox2.Checked = False Then
                    akt_richtig = False
                End If
                If CheckBox3.Checked = False Then
                    akt_richtig = False
                End If

        End Select
        Button1.Visible = False
        Button2.Visible = True
        If akt_richtig Then
            richtig = richtig + 1
            ToolStripStatusLabel4.Text = richtig.ToString("D3")
            Me.BackColor = Color.LightGreen
        Else
            falsch = falsch + 1
            ToolStripStatusLabel6.Text = falsch.ToString("D3")
            Me.BackColor = Color.LightPink
        End If

        ToolStripStatusLabel1.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel2.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel3.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel4.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel5.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel6.BackColor = System.Drawing.SystemColors.Control
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Frage_kontrollieren()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Neue_Frage()
    End Sub


    Private Sub LA_auswahl()
        la_akt(1) = DasTHWImGefügeToolStripMenuItem.Checked
        la_akt(2) = GrundlagenDerArbeitssicherheitToolStripMenuItem.Checked
        la_akt(3) = ArbeitenMitLeinenSpanngurtenToolStripMenuItem.Checked
        la_akt(4) = UmgangMitLeiternToolStripMenuItem.Checked
        la_akt(5) = StromerzeugungUndBeleuchtungToolStripMenuItem.Checked
        la_akt(6) = HolzGesteinsUndMetallbearbeitungToolStripMenuItem.Checked
        la_akt(7) = BewegenVonLastenToolStripMenuItem.Checked
        la_akt(8) = ArbeitenImamWasserToolStripMenuItem.Checked
        la_akt(9) = VerhaltenImEinsatzToolStripMenuItem.Checked
        la_akt(10) = GrundlagenRettungUndBergungToolStripMenuItem.Checked
        la_akt(11) = EinsatzgrundlagenToolStripMenuItem.Checked

        If la_akt(1) And la_akt(2) And la_akt(3) And la_akt(4) And la_akt(5) And la_akt(6) And la_akt(7) And la_akt(8) And la_akt(9) And la_akt(10) And la_akt(11) Then
            AlleAktivierenToolStripMenuItem.Checked = True
            AlleDeaktivierenToolStripMenuItem.Checked = False
            Label1.Visible = True
            CheckBox1.Visible = True
            CheckBox2.Visible = True
            CheckBox3.Visible = True
            Button1.Visible = True
            Button2.Visible = False
            Neue_Frage()
        ElseIf Not la_akt(1) And Not la_akt(2) And Not la_akt(3) And Not la_akt(4) And Not la_akt(5) And Not la_akt(6) And Not la_akt(7) And Not la_akt(8) And Not la_akt(9) And Not la_akt(10) And Not la_akt(11) Then
            AlleAktivierenToolStripMenuItem.Checked = False
            AlleDeaktivierenToolStripMenuItem.Checked = True
            Label1.Text = "Bitte min. einen Lernabschnitt aktivieren!"
            CheckBox1.Visible = False
            CheckBox2.Visible = False
            CheckBox3.Visible = False
            Button1.Visible = False
            Button2.Visible = False
        Else
            AlleAktivierenToolStripMenuItem.Checked = False
            AlleDeaktivierenToolStripMenuItem.Checked = False
            Label1.Visible = True
            CheckBox1.Visible = True
            CheckBox2.Visible = True
            CheckBox3.Visible = True
            Button1.Visible = True
            Button2.Visible = False
            Neue_Frage()
        End If

    End Sub

    Private Sub LernabschnitteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VerhaltenImEinsatzToolStripMenuItem.Click, UmgangMitLeiternToolStripMenuItem.Click, StromerzeugungUndBeleuchtungToolStripMenuItem.Click, HolzGesteinsUndMetallbearbeitungToolStripMenuItem.Click, GrundlagenRettungUndBergungToolStripMenuItem.Click, GrundlagenDerArbeitssicherheitToolStripMenuItem.Click, EinsatzgrundlagenToolStripMenuItem.Click, DasTHWImGefügeToolStripMenuItem.Click, BewegenVonLastenToolStripMenuItem.Click, ArbeitenMitLeinenSpanngurtenToolStripMenuItem.Click, ArbeitenImamWasserToolStripMenuItem.Click
        LA_auswahl()
    End Sub

    Private Sub SortiertToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SortiertToolStripMenuItem.Click
        ZufälligToolStripMenuItem.Checked = Not SortiertToolStripMenuItem.Checked
        If SortiertToolStripMenuItem.Checked Then
            akt_la = 1
            akt_nr = 0
        End If
        Neue_Frage()
    End Sub

    Private Sub ZufälligToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZufälligToolStripMenuItem.Click
        SortiertToolStripMenuItem.Checked = Not ZufälligToolStripMenuItem.Checked
        If SortiertToolStripMenuItem.Checked Then
            akt_la = 1
            akt_nr = 0
        End If
        Neue_Frage()
    End Sub

    Private Sub AlleAktivierenToolStripMenuItem_Click() Handles AlleAktivierenToolStripMenuItem.Click
        DasTHWImGefügeToolStripMenuItem.Checked = True
        GrundlagenDerArbeitssicherheitToolStripMenuItem.Checked = True
        ArbeitenMitLeinenSpanngurtenToolStripMenuItem.Checked = True
        UmgangMitLeiternToolStripMenuItem.Checked = True
        StromerzeugungUndBeleuchtungToolStripMenuItem.Checked = True
        HolzGesteinsUndMetallbearbeitungToolStripMenuItem.Checked = True
        BewegenVonLastenToolStripMenuItem.Checked = True
        ArbeitenImamWasserToolStripMenuItem.Checked = True
        VerhaltenImEinsatzToolStripMenuItem.Checked = True
        GrundlagenRettungUndBergungToolStripMenuItem.Checked = True
        EinsatzgrundlagenToolStripMenuItem.Checked = True
        LA_auswahl()
    End Sub

    Private Sub AlleDeaktivierenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlleDeaktivierenToolStripMenuItem.Click
        DasTHWImGefügeToolStripMenuItem.Checked = False
        GrundlagenDerArbeitssicherheitToolStripMenuItem.Checked = False
        ArbeitenMitLeinenSpanngurtenToolStripMenuItem.Checked = False
        UmgangMitLeiternToolStripMenuItem.Checked = False
        StromerzeugungUndBeleuchtungToolStripMenuItem.Checked = False
        HolzGesteinsUndMetallbearbeitungToolStripMenuItem.Checked = False
        BewegenVonLastenToolStripMenuItem.Checked = False
        ArbeitenImamWasserToolStripMenuItem.Checked = False
        VerhaltenImEinsatzToolStripMenuItem.Checked = False
        GrundlagenRettungUndBergungToolStripMenuItem.Checked = False
        EinsatzgrundlagenToolStripMenuItem.Checked = False
        LA_auswahl()
    End Sub

    Private Sub ZuFrageSpringenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZuFrageSpringenToolStripMenuItem.Click
        zuFragenForm.Show(Me)
        Me.Enabled = False
    End Sub
    Public Sub dialog_close()

        Select Case akt_la
            Case 1
                DasTHWImGefügeToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 2
                GrundlagenDerArbeitssicherheitToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 3
                ArbeitenMitLeinenSpanngurtenToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 4
                UmgangMitLeiternToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 5
                StromerzeugungUndBeleuchtungToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 6
                HolzGesteinsUndMetallbearbeitungToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 7
                BewegenVonLastenToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 8
                ArbeitenImamWasserToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 9
                VerhaltenImEinsatzToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 10
                GrundlagenRettungUndBergungToolStripMenuItem.Checked = True
                LA_auswahl()
            Case 11
                EinsatzgrundlagenToolStripMenuItem.Checked = True
                LA_auswahl()
            Case Else
                AlleAktivierenToolStripMenuItem_Click()
        End Select


        Label1.Text = StartForm.fragen(akt_la, akt_nr, 0)
        CheckBox1.Text = StartForm.fragen(akt_la, akt_nr, 1)
        CheckBox2.Text = StartForm.fragen(akt_la, akt_nr, 2)

        If StartForm.fragen(akt_la, akt_nr, 3) = "" Then
            CheckBox3.Visible = False
        Else
            CheckBox3.Visible = True
            CheckBox3.Text = StartForm.fragen(akt_la, akt_nr, 3)
        End If
        ToolStripStatusLabel2.Text = akt_la.ToString("D2") & "." & akt_nr.ToString("D2")
        Button1.Visible = True
        Button2.Visible = False
        CheckBox1.BackColor = Color.Transparent
        CheckBox2.BackColor = Color.Transparent
        CheckBox3.BackColor = Color.Transparent
        CheckBox1.Checked = False
        CheckBox2.Checked = False
        CheckBox3.Checked = False
        Me.Enabled = True


        ToolStripStatusLabel1.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel2.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel3.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel4.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel5.BackColor = System.Drawing.SystemColors.Control
        ToolStripStatusLabel6.BackColor = System.Drawing.SystemColors.Control
    End Sub


    Private Sub ZurücksetzenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZurücksetzenToolStripMenuItem.Click
        If SortiertToolStripMenuItem.Checked Then
            akt_la = 1
            akt_nr = 0
        End If
        richtig = 0
        falsch = 0
        ToolStripStatusLabel4.Text = 0.ToString("D3")
        ToolStripStatusLabel6.Text = 0.ToString("D3")
        LA_auswahl()
    End Sub

    Private Sub Form3_SizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
        Dim lab_poi As New Point((Me.ClientSize.Width - Panel1.Width) / 2, (Me.ClientSize.Height - Panel1.Height) / 2)
        Panel1.Location = lab_poi


        
    End Sub

    

End Class